package fmppc.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import fmppc.basics.BasicsEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 类描述:  MyBatisHandler处理对象
 *
 * @author 王雷
 * @version 1.0.0
 * @date 2022/2/24 0024 上午 9:40
 */
@Slf4j
@Component
public class MyBatisHandler implements MetaObjectHandler {

    public MyBatisHandler() {
        log.error("--------------------------------MyBatisHandler启动--------------------------------");
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        if(metaObject.getOriginalObject() instanceof BasicsEntity){
            log.debug("--------------------------------新增处理——是BasicsEntity的子类--------------------------------");
            this.setFieldValByName("createTime", new Date(), metaObject);
            this.setFieldValByName("updateTime", new Date(), metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if(metaObject.getOriginalObject() instanceof BasicsEntity){
            log.debug("--------------------------------修改处理——是BasicsEntity的子类--------------------------------");
            this.setFieldValByName("updateTime", new Date(), metaObject);
        }
    }
}
